package com.jielin.handling.controller.dict;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.jielin.handling.bean.AppResult;
import com.jielin.handling.entity.dict.Dict;
import com.jielin.handling.service.dict.DictService;

import lombok.extern.slf4j.Slf4j;

/**
 *类名称：DictionaryController
 *创建人：zhanglongdeng@163.com
 *创建时间：2019年3月19日 上午11:47:19   
 *类描述：
 */
@CrossOrigin
@RestController
@RequestMapping("/dict")
@Slf4j
public class DictController {
	@Autowired
	private DictService dictService;
	
	@RequestMapping(value="/get")
	public AppResult get(String code){
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		Dict dict = dictService.getDictByCode(code);
		log.info("dict===>{}",dict);
		data.put("dict", dict);
		result.setCode(200);
		result.setMsg("成功");
		result.setData(data);
		return result;
	}
	
	@RequestMapping(value="/list")
	public AppResult list(String parentCode){
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		Map list = dictService.getListByParentCode(parentCode);
		log.info("list===>{}",list);
		data.put("list", list);
		result.setCode(200);
		result.setMsg("成功");
		result.setData(data);
		return result;
	}
    //
	@RequestMapping(value="/dropList")
	public AppResult dropList(String parentCode){
		AppResult result = new AppResult();
		JSONObject data = new JSONObject();
		HashMap map = dictService.getListByParentCode(parentCode);
		log.info("list===>{}",map);
		data.put("list", map);
		result.setCode(200);
		result.setMsg("成功");
		result.setData(data);
		return result;
	}

}
